
import store from "@/store/index";
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: [],//扩展的按钮
  methods: {//事件扩展
    getOption(field) {
      let option;
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
    onInit () {
      this.rowKey = "Role_Id";
      let _userInfo = store.getters.getUserInfo();
      this.columns.forEach(x => {
        if (x.field == 'ParentId') {
          x.title = "上级角色";
        }
      });
      //这些配置不是必须的
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == 'ParentId') {
            item.title = "上级角色";
            //设置任意节点都能选中(默认只能选中最后一个节点)
            item.changeOnSelect = true;
            if (_userInfo.roleID == 1) {
              item.hidden = true;
              item.required = false;
            } else {
              item.hidden = false;
              item.required = true;
            }
          }
          if (item.field == 'Dept_Id') {
            if (_userInfo.roleID == 1) {
              item.hidden = false;
              item.required = true;
            } else {
              item.hidden = true;
              item.required = false;
            }
          }
        })
      })
    },
    rowClick ({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    modelOpenAfter (row) {
      let issecondDistri = this.getOption('issecondDistri')
      if (this.currentAction == 'Add') {
        issecondDistri.disabled = false
      } else {
        issecondDistri.disabled = true
      }
    },
    searchBefore (params) {//判断加载根节点或子节点
      //没有查询条件，默认查询返回所有根节点数据
      if (!params.wheres.length) {
        params.value = 1;
      }
      return true;
    },
    loadTreeChildren (tree, treeNode, resolve) { //加载子节点
      let url = `api/Roles/getTreeTableChildrenData?roleId=${tree.Role_Id}`;
      this.http.post(url, {}).then(result => {
        resolve(result.rows)
      })
    },
  }
};
export default extension;
